<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>用户注册</title>
<link type="text/css" rel="stylesheet" href="css/style.css;">
<base href="${pageContext.request.contextPath}/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#E7ECEF">
	<center>
		<form method="post">
			<table border="0" cellspacing="0" cellpadding="0"
				style="margin-top: 130">
				<tr>
					<td><img src="images/logon_top.gif"></td>
				</tr>
				<tr height="180">
					<td background="images/logon_middle.gif" align="center"
						valign="top">
						<table border="0" width="90%" cellspacing="0" cellpadding="0">
							<tr height="50">
								<td colspan="2"></td>
							</tr>
							<tr height="30">
								<td align="right" width="40%">用户名：&nbsp;&nbsp;</td>
								<td style="text-indent: 5"><input type="text"
									name="username" size="30" value="" id="username"
									onblur="checkusername()" /><br>
								<span style="color: red;" id="msg_n"></span></td>
							</tr>
							<tr height="30">
								<td align="right">密&nbsp;&nbsp;码：&nbsp;&nbsp;</td>
								<td style="text-indent: 5"><input type="password"
									name="password" size="30" id="password"
									onblur="checkpassword()" /><br>
								<span style="color: red;" id="msg_p"></span></td>
							</tr>
							<tr height="30">
								<td align="right">验证码：&nbsp;&nbsp;</td>
								<td style="text-indent: 5;"><span> <input
										style="vertical-align: middle" type="text" name="yzcode"
										size="19" id="yzcode" /> <img style="vertical-align: middle"
										id="yzimg" alt="验证码图片" height="22" width="60" src="yzcode.jpg"
										onclick="refresh(this)" /> <script type="text/javascript">
											function refresh(obj) {
												obj.src = "yzcode.jpg?id="
														+ Math.random();
											}
										</script>
								</span> <br>
								<span style="color: red;" id="msg_y"></span></td>
							</tr>
							
							
							<tr height="60">
								<td></td>
								<td><input type="submit" id="btn_sub" value="注册"
									onclick="return subDate();" /> <input type="reset" id="btn_rs"  value="重置" />
									<a id="log_Login_action_" href="./">[返回首页]</a></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td><img src="images/logon_end.gif"></td>
				</tr>
			</table>
		</form>
	</center>
	<script src="js/jquery.min.js"></script>
	<script src="js/check.js"></script>
	<script src="js/md5.js"></script>
	<script type="text/javascript">
		function subDate() {
			var name = $("#username").val();
			var pwd = $("#password").val();
			var yzcode = $("#yzcode").val();
			if (yzcode.length < 4) {
				$("#msg_y").html('验证码有误！');
				return false;
			} else {
				$("#msg_y").html('');
			}
			if (!isUserName(name)) {
				$("#msg_n").html('用户名只能有数字,字母,_，长度3-16！');
				return false;
			} else {
				$("#msg_n").html('');
			}

			if (pwd.length < 5) {
				$("#msg_p").html('密码太短，至少5位！');
				return false;
			} else {
				$("#msg_p").html('');
			}
			pwd = hex_md5(pwd).toUpperCase();
			$.post("tosign", {
				yzcode : trim(yzcode),
				name : trim(name),
				pwd : trim(pwd)
			}, function(data) {
				if (data.status - 200 == 0) {
					$("#btn_sub").remove();
					$("#btn_rs").remove();
					$("#msg_y").html('注册成功');
					 cleanCookie('username', 'password');
					var t1 = window.setInterval(autorun,1000); 
					return true;
				} else {
					$("#msg_y").html('发生未知错误');
				}
				var timestamp = new Date().getTime();  
	            $("#yzimg").attr("src", 'yzcode.jpg' + '?' +timestamp );  
	            document.getElementById("password").value = '';
				if (data.status - 400 == 0) {
					$("#msg_y").html(data.msg);
					return false;
				} else {
					$("#msg_y").html('');
				}
				
				if (data.status - 300 == 0) {
					$("#msg_n").html(data.msg);
					return false;
				} else {
					$("#msg_n").html('');
				}
				
				if (data.status - 1 == 0) {
					$("#msg_n").html(data.msg);
					return false;
				} else {
					$("#msg_n").html('');
				}
				if (data.status - 2 == 0) {
					$("#msg_p").html(data.msg);
					return false;
				} else {
					$("#msg_p").html('');
				}
				
			});
			
			return false;
		}
		
		var itime = 5;
		function autorun(){
			itime = itime - 1;
			$("#msg_y").html('注册成功，' + itime + '秒后自动返回...' );
			if(itime == 0){
				window.location.href="./login";
			}
		}
		
		$("#username").focus();
	</script>
</body>
</html>